package com.lt.bcra.controller.questionnaire;


import com.lt.bcra.entity.BcraFamilyHistory;
import com.lt.bcra.exception.BaseException;
import com.lt.bcra.service.BcraFamilyHistoryService;
import com.lt.bcra.result.ResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 个人及家族病史表 前端控制器
 * </p>
 *
 * @author LuoTian
 * @since 2022-05-25
 */
@Api(tags = "5.个人及家族病史表")
@CrossOrigin //跨域可以前端配置
@RestController
@RequestMapping("bcra/familyHistory")
public class BcraFamilyHistoryController {

    private static Logger log = LoggerFactory.getLogger(BcraFamilyHistoryController.class);

    @Autowired
    private BcraFamilyHistoryService bcraFamilyHistoryService;


    @PostMapping("/creatFamilyHistory")
    @ApiOperation("填写家族病史")
    @ApiParam(value = "bcraFamilyHistoryList")
    public ResultData creatNew(@RequestBody List<BcraFamilyHistory> bcraFamilyHistoryList) throws BaseException {
        if (log.isDebugEnabled()) log.debug("创建家族病史表 BcraFamilyHistoryController");

        return bcraFamilyHistoryService.saveModule(bcraFamilyHistoryList);
    }

    @PostMapping("/updateFamilyHistory")
    @ApiOperation("修改家族病史")
    @ApiParam(value = "bcraFamilyHistoryList")
    public ResultData update(@RequestBody List<BcraFamilyHistory> bcraFamilyHistoryList) throws BaseException {
        if (log.isDebugEnabled()) log.debug("修改家族病史表 BcraFamilyHistoryController");

        return bcraFamilyHistoryService.updateModule(bcraFamilyHistoryList);
    }

    @DeleteMapping("/deleteFamilyHistory")
    @ApiOperation("删除家族病史")
    @ApiParam(value = "问卷编号")
    public ResultData delete(String questionnaireCode) throws BaseException{
        if (log.isDebugEnabled()) log.debug("删除家族病史表 BcraFamilyHistoryController");

        return bcraFamilyHistoryService.removeByQuesCode(questionnaireCode);
    }

    @GetMapping("/getFamilyHistory")
    @ApiOperation("查看家族病史")
    @ApiParam(value = "问卷编号")
    public ResultData list(String questionnaireCode) throws BaseException{
        if (log.isDebugEnabled()) log.debug("删除家族病史表 BcraFamilyHistoryController");

        return bcraFamilyHistoryService.selectByQuesCode(questionnaireCode);
    }
}

